package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func test1() {
	sum := 0
	for i := 1; i <= 100; i++ {
		sum += i
	}
	fmt.Println(sum)
}

/*
将整数转成二进制
*/
func convertToBinary(num int) string {
	binaryStr := ""
	if num == 0 {
		return "0"
	}
	/*for {
		if num == 0 {
			break
		}
		if num%2 == 0 {
			binaryStr = "0" + binaryStr
		} else {
			binaryStr = "1" + binaryStr
		}
		num /= 2
	}*/
	/*for {
		if num == 0 {
			break
		}
		binaryStr = strconv.Itoa(num%2) + binaryStr
		num /= 2
	}*/
	for ; num > 0; num /= 2 {
		binaryStr = strconv.Itoa(num%2) + binaryStr
	}

	return binaryStr
}

func printFile(filename string) {
	file, err := os.Open(filename)
	if err != nil {
		panic(err)
	}

	scanner := bufio.NewScanner(file)

	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}
}

/*
死循环
*/
func forNotStop() {
	for {
		fmt.Println("abcdefghijklmnopqrstuvwxyz")
	}
}

func main() {
	test1()

	fmt.Println(convertToBinary(10))
	fmt.Println(convertToBinary(16))
	fmt.Println(convertToBinary(0))

	printFile("top/jacktgq/basic/abc.txt")

	forNotStop()
}
